package jsoner

import (
	"errors"

	jsoniter "github.com/json-iterator/go"
)

type jsonIterator struct {
	lib         jsoniter.API
	libUnEscape jsoniter.API
}

func (m *jsonIterator) Valid(v []byte) bool {
	return m.lib.Valid(v)
}
func (m *jsonIterator) Marshal(v any) ([]byte, error) {
	return m.lib.Marshal(v)
}
func (m *jsonIterator) MarshalToString(v any) (string, error) {
	return m.lib.MarshalToString(v)
}
func (m *jsonIterator) MarshalWithoutEscape(v any) ([]byte, error) {
	return m.libUnEscape.Marshal(v)
}
func (m *jsonIterator) MarshalToStringWithoutEscape(v any) (string, error) {
	return m.libUnEscape.MarshalToString(v)
}
func (m *jsonIterator) Unmarshal(data []byte, objRef any) error {
	if data == nil {
		return errors.New("unmarshal data<[]byte> is nil")
	}
	if objRef == nil {
		return errors.New("unmarshal objRef<any> is nil")
	}
	return m.lib.Unmarshal(data, objRef)
}
func (m *jsonIterator) UnmarshalFromString(str string, objRef any) error {
	if objRef == nil {
		return errors.New("unmarshalFromString objRef<any> is nil")
	}
	return m.lib.UnmarshalFromString(str, objRef)
}
